#include<bits/stdc++.h>
#define i64 long long
#define ull unsigned long long
using namespace std;

const int N = 1e6 + 10, INF = 0x3f3f3f3f;
const int mod = 1000000007;


void solve()
{
    int n;
    while (cin >> n)
    {
        i64 a1, a2, b1, b2;
        cin >> a1 >> a2 >> b1 >> b2;
        vector<vector<i64>> A(n, vector<i64>(n));
        auto B = A;
        vector<i64> r(n);

        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                A[i][j] = i * a1 % mod + j * a2 % mod;
                B[i][j] = i * b1 % mod + j * b2 % mod;
                r[i] = (r[i] + B[i][j]) % mod;
            }
        }

        i64 ans = 0;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                ans = (ans + A[i][j] * r[j] % mod) % mod;
            }
        }
        cout << ans << "\n";
    }
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    //cin>>T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}